var _winW = $(window).width();
var _marginCW = $(".home.content-wrap .screen3 .marginC").width()/3;
var _screen3Total = 3;
var _screen3Current = 0;
var circleFx = function(){
	_winW = $(window).width();
	var _width;
	var _max = 1600;
	var _min = 1340;
	if(_winW >=_max){
		_width = 340;
	} else if(_winW <= _min ){
		_width = 300;
	} else {
		_width = (1- (_max-_winW)/(_max-_min))*40+300;
	}
	$(".home.content-wrap .screen3 .content li .box").css({"width":_width+"px"});

	_marginCW = $(".home.content-wrap .screen3 .marginC").width()/3;

	$(".home.content-wrap .screen3 .content li").each(function($i){
		$(this).css({"left":$i*_marginCW+"px"});
	});


	resizeFont();

}

var createBtnHome = function(){
	$(".home.content-wrap .screen3 .control .prev").click(function(){
		contentMoving(false, $(this));
	});
	$(".home.content-wrap .screen3 .control .next").click(function(){
		contentMoving(true, $(this));
	});
}

function contentMoving($b, $this) {
	_screen3Current = ($b) ? _screen3Current+1 : _screen3Current-1;
	_screen3Current = Math.max(Math.min(_screen3Current, (_screen3Total-1)), 0);
	var _this = $(".home.content-wrap .screen3 .content");
	_this.css("borderSpacing", 0);
	_this.parent().find(".bg-line").css({"opacity":0, "display":"none"});
	_this.stop().animate({  borderSpacing: 1 }, {
		step: function(now,fx) {
			_now =  -$(".home.content-wrap .screen3 .marginC").width()*_screen3Current;
			$(this).css({'transform':'matrix(1,0,0,1,'+_now+',0)',
						'-webkit-transform':'matrix(1,0,0,1,'+_now+',0)',
						'-moz-transform':'matrix(1,0,0,1,'+_now+',0)'
			});
			_this.parent().find(".bg-line").css({"display":"block"});
		},duration:500,
		easing :'easeInOutCubic',
		complete: function(){
			_this.parent().find(".bg-line").css({"opacity":1});
		}
	});

	$this.siblings(".num").find("em").text(_screen3Current+1);
	if(_screen3Current===0){
		$(".home.content-wrap .screen3 .control .prev").attr("disabled", "disabled");
	} else if(_screen3Current === _screen3Total-1){

		$(".home.content-wrap .screen3 .control .next").attr("disabled", "disabled");
	} else {
		$(".home.content-wrap .screen3 .control .prev").removeAttr("disabled");
		$(".home.content-wrap .screen3 .control .next").removeAttr("disabled");

	}
}

function resizeNewsContents() {
	var _now =  -$(".home.content-wrap .screen3 .marginC").width()*_screen3Current;
	$(".home.content-wrap .screen3 .content").css({'transform':'matrix(1,0,0,1,'+_now+',0)',
				'-webkit-transform':'matrix(1,0,0,1,'+_now+',0)',
				'-moz-transform':'matrix(1,0,0,1,'+_now+',0)'
	});
}

var resizeFont = function() {
	var _max = 1900;
	var _min =  1080;
	var _percent =($(".home.content-wrap .screen0").width() - _min) / (_max-_min);
	$(".home.content-wrap .screen0 .title").css("font-size", _percent*12+48);
}

$(window).load(function(){
	$('.gnb > .btn').on('click', function(e) {
		setTimeout(function() {
			resizeNewsContents();
		},500);
	});
	
	$( window ).resize(function() {
		circleFx();
		resizeNewsContents();
	});

	createBtnHome();
	$(window).trigger("resize");

});


function autoPlay() {
	var _video = $("#movie");
	_video.on('timeupdate', function(){
		if(_video[0].currentTime >= 8 && !_isTxtView){
			$(".home .wrap-holder .homeTitle .title").css("opacity",1);
			$(".home .wrap-holder .homeTitle .title").addClass("txt-mask");
			$(".home .wrap-holder .homeTitle .txt").addClass("animate");
			_isTxtView = true;
		}
		if(_video[0].currentTime >= _video[0].duration){
		_video.remove();
		$("video.looping")[0].currentTime = 0;
		$("video.looping").css('visibility', 'visible');
		}
	});
}


var _isTxtView = false;
$(window).ready(function(){
	autoPlay();
});
